<!--# layout("/common/layout.html",{"jsBase":"/js/plandata/tDPlanningData/"}){ -->
<form class="layui-form layui-form-pane" id="addForm"  lay-filter="editform">
    <input type="hidden" name="id" id="id" >
<!--    <input type="hidden" name="univName" id="univName">-->
    <input type="hidden" name="univId" id="univId">
    <br>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" >省份</label>
                <div class="layui-input-inline">
                    <layui:simpleDataSelect name="provinceId"  data="${provinceList}" value="${tDPlanningData.provinceId}"
                                            attrId="provId" attrName="provName" laySearch="true" layFilter="colFilter" id="provinceId" />
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" >文理科</label>
                <div class="layui-input-inline" >
                    <select  class="select" name="majorTypeId" id="majorTypeId" lay-filter="typeselect">
                        <option value="" >请选择</option>
                        <option value="1" ${tDPlanningData.majorTypeId==1?'selected':''}>文科</option>
                        <option value="2" ${tDPlanningData.majorTypeId==2?'selected':''}>理科</option>
                    </select>
                </div>
            </div>

        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label" >年份</label>
                <div class="layui-input-inline">
                    <input type="text" name="year" id="year" autocomplete="off" maxlength="50" class="layui-input" value="${tDPlanningData.year}" lay-verify="required|number">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label" >批次</label>
                <div class="layui-input-inline">
                    <select class="select" name="batchId" id="batchId" selectValue="" promtion="请选择" lay-search lay-filter="batchselect">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label" >学校</label>
                <div class="layui-input-inline">
                    <input type="text" name="univName" id="univName" class="layui-input" value="${tDPlanningData.univName}" lay-verify="required">

                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">招生人数</label>
                <div class="layui-input-inline">
                       <input type="text" name="plan" id="plan" autocomplete="off" maxlength="50" class="layui-input" value="${tDPlanningData.plan}" lay-verify="required|number">
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">

            <div class="layui-inline">
            <label class="layui-form-label">学校代码</label>
				<div class="layui-input-inline">
                    <input type="text" name="univCode" id="univCode" autocomplete="off" maxlength="50" class="layui-input" value="${tDPlanningData.univCode}" lay-verify="required">
				</div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">学校测评</label>
                <div class="layui-input-block" style="width:512px">
                    <textarea name="univEvaluation"  id="univEvaluation" placeholder="请输入" class="layui-textarea" >${tDPlanningData.univEvaluation}</textarea>
                </div>
            </div>

        </div>
    </div>
    <layui:submitButtons id="addButton" />
</form>
<!--#} -->
<script>
layui.extend({
    loading: '../../../plugins/layui_extends/loading/loading',
}).define([ 'form', 'laydate', 'table','loading','tDPlanningDataApi'], function(exports) {
    var form = layui.form;
    var tDPlanningDataApi = layui.tDPlanningDataApi;
    var index = layui.index;
    var isNew = true;
    <!--# if(!(isEmpty(tDPlanningDataJson))){  -->
    isNew = false;
    <!--# } -->
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                // $("#addButton").hide();
                // $("#addButton-loading").show();
                // $("#addButton-loading").loading();

                var data =  $("#addForm").serializeJson();
                if(data.provinceId==null||data.provinceId==""){
                    Common.info("省份不能为空");
                    return ;
                }
                if(data.majorTypeId==null||data.majorTypeId==""){
                    Common.info("文理科不能为空");
                    return ;
                }
                if(data.batchId==null||data.batchId==""){
                    Common.info("批次不能为空");
                    return ;
                }
                // if(data.umId==null||data.umId==""){
                //     Common.info("学校不能为空");
                //     return ;
                // }

                form.on('submit(form)', function(){
                    tDPlanningDataApi.saveForm(isNew,$('#addForm'),function(){
                        parent.window.dataReload();
                        Common.info("保存成功");
                        Lib.closeFrame();
                    });
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }

    }
    view.init();

    <!--# if(!(isEmpty(TDPlanningDataJson))){  -->
    var formJson = ${TDPlanningDataJson};
    form.val("editform",formJson);
    <!--# } -->


    $("#umId").val("${tDPlanningData.umId }");

    setBatch($("#year").val());

    //省份选择事件监听
    form.on('select(colFilter)', function(data){
        setBatch($("#year").val());
    });

    form.on('select(typeselect)', function(data){
        setBatch($("#year").val());
    });

    form.on('select(umIdFilter)', function(data){
       $("#univId").val(data.value.substring(0,5));
       $("#univName").val($("#umId").find("option:selected").text());
    });

    $("#year").blur(function(){
        setBatch($("#year").val());
    });

    function setBatch(year) {
        var id = $('#provinceId option:selected').val();
        var type = $('#majorTypeId option:selected').val();
        $.ajax({
            type: 'POST',
            url: "${ctxPath}/plandata/tDPlanningData/getBatch.json",
            data: {
                id:id,
                year:year,
                type:type
            },
            dataType:'json',
            success: function(data){
                $("#batchId").html("");
                var option1 = $("<option>").val("").text("请选择");
                $("#batchId").append(option1);
                $.each(data, function(key, val) {
                    var option1 ;
                    if(val.value == "${tDPlanningData.batchId }"){
                        option1 = $("<option selected>").val(val.value).text(val.key);
                    }else{
                        option1 = $("<option>").val(val.value).text(val.key);
                    }
                    $("#batchId").append(option1);
                });
                form.render('select');

            }
        });
    }


});
</script>
